﻿using App_1.Contracts;

namespace App_1.Data.Repositoriescs
{
    /// <summary>
    /// 仓储包装类
    /// </summary>
    public class RepositoryWrapper : IRepositoryWrapper
    {
        private readonly GameManagementDbContext _dbContext;
        private IPlayerRepository _player;
        private ICharacterRepository _character;

        public RepositoryWrapper(GameManagementDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        ///此处采用（属性-字段）的方式实现， 也可使用依赖注入的方式实现仓储包装类
        public IPlayerRepository Player
        { get { return _player ??= new PlayerRepository(_dbContext); } }

        public ICharacterRepository Character
        { get { return _character ??= new CharacterRepository(_dbContext); } }

        public Task<int> SaveChangesAsync()
        {
            return _dbContext.SaveChangesAsync();
        }
    }
}
